<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function hex2rgb(hex) {
            let reg = /^#[0-f]*6/g
            console.log(reg.test(hex))
            if (reg.test(hex)) {
                return hex
            }
            let arr = hex.split("#")
            let str = arr[1]
            let str1 = str.slice(0, 1)
            let str2 = str.slice(2, 3)
            let str3 = str.slice(4, 5)
            let result = `rgb(${parseInt(str1, 16)},${parseInt(str2, 16)},${parseInt(str3, 16)})`
            return result
        }
        console.log(hex2rgb("#ffffff"))
    </script>
</body>

</html>